"""
vas rocket_mq 测试工具
"""
import time

from rocketmq.client import PushConsumer, ConsumeStatus

HOST = '127.0.0.1:9876'
TOPIC = 'ChannelResult'

msg_counter = 0


def callback(msg):
    global msg_counter
    msg_counter += 1
    data = msg.body.decode('utf8')
    print('get msg', msg.id, "total", msg_counter, "body", data[:10])
    return ConsumeStatus.CONSUME_SUCCESS


if __name__ == '__main__':
    consumer = PushConsumer('CID-TEST')
    consumer.set_name_server_address(HOST)
    consumer.subscribe(TOPIC, callback)
    consumer.start()

    while True:
        print(TOPIC)
        time.sleep(3600)

    consumer.shutdown()
